package demo1;

public class Test {
    public static void main(String[] args) {
        Animal animal = new Dog("多吉",10);

        if (animal instanceof Dog) {
            Dog dog = (Dog) animal;
            dog.bark();
            System.out.println("animal 引用的是 Dog这样的对象");//111
        }else{
            System.out.println("animal 引用的是 Dog这样的对象");
        }
        if (animal instanceof Bird) {
            Bird bird = (Bird) animal;
            bird.fly();
            System.out.println("animal 引用的是 Bird这样的对象");//111
        }else{
            System.out.println("animal 引用的是 Bird这样的对象");
        }
    }
    public static void func(Animal animal) {
        animal.eat();
    }

    public static Animal func2(int a) {
        if (a == 1) {
            return new Dog("多吉",10);

        }else {
            return new Bird("臭野鸡",19);
        }
    }
    public static void main3(String[] args) {
        Dog dog = new Dog("多吉",10);
        Bird bird = new Bird("臭野鸡",19);
        func(dog);
        func(bird);
    }
    public static void main2(String[] args) {
       /* Dog dog = new Dog("多吉",10);
        Animal animal = dog;*/

        Animal animal = new Dog("多吉",10);
        animal.eat();

    }
    public static void main1(String[] args) {
        Dog dog = new Dog("多吉",10);
        dog.eat();
    }
}


